
/*
 * This filter converts Fahrenheit to Celsius
 * @author Team 10
 */
public class TemperatureFilter extends FilterFramework2
{
	public TemperatureFilter() 
	{
		// this filter has 1 input and 1 output
		super(1, 1);
	}

	public void run()
    {
		while (true)
		{
			try
			{
				// This measurement will aid with extracting and setting specific data within
				// an entire Data Frame
				Measurement measurement = new Measurement();
				
				// read bytes from Pipe 0
				measurement.readByteStream(this, 0);

				// grab the temperature value from the dataframe
				Double temp = (Double)measurement.getValue(4);
				
				// convert the value to celsius
				temp = ((temp-32)*5)/9;
				
				// save the value back into the dataframe
				measurement.setValue(4, temp);
				
				// write the cleaned data frame to the pipe
				measurement.writeByteStream(this, 0);
			} // try

			catch (EndOfStreamException e)
			{
				CloseInputPorts(0);
				CloseOutputPorts(0);
				break;

			} // catch

		} // while

   } // run
}
